<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script>
        
        var str = "apple";
        var index = str.indexOf('p'); 
        var num = 0;
        while(index !== -1){
            console.log(index);
            num++;
            index = str.indexOf('p',index + 1);
        }  
        console.log('p出现的次数是：' + num); 

        var arr = ['red','blue','red','green','pink','red'];
        var red = arr.indexOf('red');
        var num1=0;
        while(red !== -1 ){
           console.log(red);
           num1++;
           red=arr.indexOf('red',red + 1);
       }
        console.log('red出现的次数是：' + num1);
     
 
    </script>
</head>
<body>
    
</body>
</html>